package com.spelet.simulation;


import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;

import com.spelet.StaticSprites;
import com.spelet.VariableCollection;


public class Block {
	public boolean moving;
	public int type;
	private Sprite spriteToDraw;
	int moveTimer;
	int state;
	public int tileX, tileY;
	public boolean hasLamp;
	public float lampX, lampY, lightScale, minLightScale, maxLightScale;
	boolean lightScaleInc;
	int renderAtRow;
	int animStep2;
	boolean right;
	boolean up;
	boolean left;
	int size;
	boolean locked;

	public Block(int type, int x, int y){
		tileX = x;
		tileY = y;
		renderAtRow = y;
		this.type = type;
		if(type == VariableCollection.moveBlock){
			spriteToDraw = StaticSprites.moveBlockBase;
		} else if(type == VariableCollection.wall){
			minLightScale = 1.9f;
			maxLightScale = 2.1f;
		} else if (type == VariableCollection.key_red) {
			spriteToDraw = StaticSprites.redkey[0];
		} else if (type == VariableCollection.key_blue) {
			spriteToDraw = StaticSprites.bluekey[0];
		} else if (type == VariableCollection.key_yellow) {
			spriteToDraw = StaticSprites.yellowkey[0];
		}else if (type == VariableCollection.door_red) {
			spriteToDraw = StaticSprites.dooropening[0];
			state = VariableCollection.doorclosed;
		} else if (type == VariableCollection.door_blue) {
			spriteToDraw = StaticSprites.dooropeningB[0];
			state = VariableCollection.doorclosed;
		} else if (type == VariableCollection.door_yellow) {
			spriteToDraw = StaticSprites.dooropeningY[0];
			state = VariableCollection.doorclosed;
		} else if (type == VariableCollection.goal) {
			spriteToDraw = StaticSprites.goal[0];
		} else if (type == VariableCollection.boulder) {
			spriteToDraw = StaticSprites.boulderBase;
		} else if (type == VariableCollection.mergeblock) {
			lightScale = 2;
			minLightScale = 1.9f;
			maxLightScale = 2.1f;
			spriteToDraw = StaticSprites.mergeBlockBaseAnim[0];
		}
	}

	public void setSprite(int x, int y, Block[][] blocks) {
		if (type == VariableCollection.wall) { 
			int calcValue = 0;

			try {
				if (blocks[x-1][y+1].type == VariableCollection.wall) {
					calcValue+=1;
				}
			} catch (ArrayIndexOutOfBoundsException e ) {
				calcValue+=1;
			}

			try {
				if (blocks[x][y+1].type == VariableCollection.wall) {
					calcValue+=2;
				}
			} catch (ArrayIndexOutOfBoundsException e ) {
				calcValue+=2;
			}

			try {
				if (blocks[x+1][y+1].type == VariableCollection.wall) {
					calcValue+=4;
				}
			} catch (ArrayIndexOutOfBoundsException e ) {
				calcValue+=4;
			}

			try {
				if (blocks[x-1][y].type == VariableCollection.wall) {
					calcValue+=8;
				}
			} catch (ArrayIndexOutOfBoundsException e ) {
				calcValue+=8;
			}

			try {
				if (blocks[x+1][y].type == VariableCollection.wall) {
					calcValue+=16;
				}
			} catch (ArrayIndexOutOfBoundsException e ) {
				calcValue+=16;
			}

			try {
				if (blocks[x-1][y-1].type == VariableCollection.wall) {
					calcValue+=32;
				}
			} catch (ArrayIndexOutOfBoundsException e ) {
				calcValue+=32;
			}

			try {
				if (blocks[x][y-1].type == VariableCollection.wall) {
					calcValue+=64;
				}
			} catch (ArrayIndexOutOfBoundsException e ) {
				calcValue+=64;
			}
			try {
				if (blocks[x+1][y-1].type == VariableCollection.wall) {
					calcValue+=128;
				}
			} catch (ArrayIndexOutOfBoundsException e ) {
				calcValue+=128;
			}
			spriteToDraw = StaticSprites.walls[StaticSprites.wallTranslation[calcValue]];
			if (calcValue < 255) {
				if (MathUtils.random(20) < 3) {
					this.hasLamp = true;
					this.lampX = 0;
					this.lampY = 32;
					this.lightScale = 2;
				}
			}
		}

	}
	public void update(Simulation sim){
		moveTimer += Gdx.graphics.getDeltaTime()*1000;
		if (type == VariableCollection.wall) {
			animStep2 += Gdx.graphics.getDeltaTime()*1000;
			if (animStep2 > 30) {
				if (hasLamp) {
					if (lightScaleInc) {
						lightScale += 0.01f;
						if (lightScale > maxLightScale) {
							lightScale = maxLightScale;
							lightScaleInc = false;
						}
					} else {
						lightScale -= 0.01f;
						if (lightScale < minLightScale) {
							lightScale = minLightScale;
							lightScaleInc = true;
						}
					}
				}
				animStep2 = 0;
			}
		} else if (type == VariableCollection.moveBlock) { 
			if (state == VariableCollection.blockMoveRight) {
				right = true;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= 40) {
					spriteToDraw = StaticSprites.moveblockRight[0];
				} else if (animStep2 <= 80){
					spriteToDraw = StaticSprites.moveblockRight[1];
				} else if (animStep2 <= 120){
					spriteToDraw = StaticSprites.moveblockRight[2];
				} else if (animStep2 <= 160){
					spriteToDraw = StaticSprites.moveblockRight[3];
				} else if (animStep2 <= 200){
					spriteToDraw = StaticSprites.moveblockRight[4];
				} else if (animStep2 <= 240){
					spriteToDraw = StaticSprites.moveblockRight[5];
				} else if (animStep2 <= 280){
					spriteToDraw = StaticSprites.moveblockRight[6];
				} else if (animStep2 <= 320){
					spriteToDraw = StaticSprites.moveblockRight[7];
				} else {
					right = false;
					locked = false;
					spriteToDraw = StaticSprites.moveBlockBase;
					if (sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.hole) {
						sim.map.terrainBlocks[tileX][tileY].setState(VariableCollection.fillingHole);
						type = VariableCollection.nothing;
					}
					state = VariableCollection.inactive;;
				}
			} else if (state == VariableCollection.blockMoveLeft) {
				right = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= 40) {
					spriteToDraw = StaticSprites.moveblockLeft[0];
				} else if (animStep2 <= 80){
					spriteToDraw = StaticSprites.moveblockLeft[1];
				} else if (animStep2 <= 120){
					spriteToDraw = StaticSprites.moveblockLeft[2];
				} else if (animStep2 <= 160){
					spriteToDraw = StaticSprites.moveblockLeft[3];
				} else if (animStep2 <= 200){
					spriteToDraw = StaticSprites.moveblockLeft[4];
				} else if (animStep2 <= 240){
					spriteToDraw = StaticSprites.moveblockLeft[5];
				} else if (animStep2 <= 280){
					spriteToDraw = StaticSprites.moveblockLeft[6];
				} else if (animStep2 <= 320){
					spriteToDraw = StaticSprites.moveblockLeft[7];
				} else {
					spriteToDraw = StaticSprites.moveBlockBase;
					locked = false;
					if (sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.hole) {
						sim.map.terrainBlocks[tileX][tileY].setState(VariableCollection.fillingHole);
						type = VariableCollection.nothing;
					} else if(sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.dirt){
						sim.map.terrainBlocks[tileX][tileY].type = VariableCollection.dirtStuck;
						type = VariableCollection.nothing;
					}
					state = VariableCollection.inactive;;
				}
			} else if (state == VariableCollection.blockMoveDown) {
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step*1) {
					spriteToDraw = StaticSprites.moveblockDown[0];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.moveblockDown[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.moveblockDown[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.moveblockDown[3];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.moveblockDown[4];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.moveblockDown[5];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.moveblockDown[6];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.moveblockDown[7];
				} else if (animStep2 <= step*9) {
					spriteToDraw = StaticSprites.moveblockDown[8];
				} else if (animStep2 <= step*10) {
					spriteToDraw = StaticSprites.moveblockDown[9];
				} else {
					spriteToDraw = StaticSprites.moveBlockBase;
					locked = false;
					if (sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.hole) {
						sim.map.terrainBlocks[tileX][tileY].setState(VariableCollection.fillingHole);
						type = VariableCollection.nothing;
					} else if(sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.dirt){
						sim.map.terrainBlocks[tileX][tileY].type = VariableCollection.dirtStuck;
						type = VariableCollection.nothing;
					}
					state = VariableCollection.inactive;;
				}
			} else if (state == VariableCollection.blockMoveUp) {
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				up = true;
				int step = 40;
				if (animStep2 <= step*1) {
					spriteToDraw = StaticSprites.moveblockUp[0];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.moveblockUp[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.moveblockUp[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.moveblockUp[3];
				} else if (animStep2 <= step*5){
					//spriteToDraw = StaticSprites.moveblockUp[4];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.moveblockUp[5];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.moveblockUp[6];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.moveblockUp[7];
				} else if (animStep2 <= step*9) {
					spriteToDraw = StaticSprites.moveblockUp[8];
				} else if (animStep2 <= step*10) {
					spriteToDraw = StaticSprites.moveblockUp[9];
				} else {
					spriteToDraw = StaticSprites.moveBlockBase;
					locked = false;
					up = false;
					if (sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.hole) {
						sim.map.terrainBlocks[tileX][tileY].setState(VariableCollection.fillingHole);
						type = VariableCollection.nothing;
					} else if(sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.dirt){
						sim.map.terrainBlocks[tileX][tileY].type = VariableCollection.dirtStuck;
						type = VariableCollection.nothing;
					}
					state = VariableCollection.inactive;
					sim.map.renderAtRows.get(renderAtRow).removeValue(this, true);
					renderAtRow++;
					sim.map.renderAtRows.get(renderAtRow).add(this);
				}
			} else if (state == VariableCollection.moveToDirtRight){
				right = true;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step*1) {
					spriteToDraw = StaticSprites.dirtAnim[2];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.dirtAnim[3];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.dirtAnim[4];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.dirtAnim[5];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.dirtAnim[6];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.dirtAnim[7];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.dirtAnim[8];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.dirtAnim[9];
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.dirtAnim[10];
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.dirtAnim[11];
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.dirtAnim[12];
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.dirtAnim[13];
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.dirtAnim[14];
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.dirtAnim[15];
				} else if (animStep2 <= step*15){
					spriteToDraw = StaticSprites.dirtAnim[16];
				} else if (animStep2 <= step*16){
					spriteToDraw = StaticSprites.dirtAnim[17];
				} else if (animStep2 <= step*17){
					spriteToDraw = StaticSprites.dirtAnim[18];
				} else if (animStep2 <= step*18){
					spriteToDraw = StaticSprites.dirtAnim[19];
				} else if (animStep2 <= step*19){
					spriteToDraw = StaticSprites.dirtAnim[20];
				} else {
					locked = false;
					sim.map.terrainBlocks[tileX][tileY].type = VariableCollection.dirtStuck;
					type = VariableCollection.nothing;
				} 
			} else if (state == VariableCollection.moveToDirtLeft){
				left = true;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step*1) {
					spriteToDraw = StaticSprites.dirtAnimLeft[2];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.dirtAnimLeft[3];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.dirtAnimLeft[4];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.dirtAnimLeft[5];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.dirtAnimLeft[6];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.dirtAnimLeft[7];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.dirtAnimLeft[8];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.dirtAnimLeft[9];
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.dirtAnimLeft[10];
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.dirtAnimLeft[11];
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.dirtAnimLeft[12];
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.dirtAnimLeft[13];
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.dirtAnimLeft[14];
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.dirtAnimLeft[15];
				} else if (animStep2 <= step*15){
					spriteToDraw = StaticSprites.dirtAnimLeft[16];
				} else if (animStep2 <= step*16){
					spriteToDraw = StaticSprites.dirtAnimLeft[17];
				} else if (animStep2 <= step*17){
					spriteToDraw = StaticSprites.dirtAnimLeft[18];
				} else if (animStep2 <= step*18){
					spriteToDraw = StaticSprites.dirtAnimLeft[19];
				} else if (animStep2 <= step*19){
					spriteToDraw = StaticSprites.dirtAnimLeft[20];
				} else {
					locked = false;
					sim.map.terrainBlocks[tileX][tileY].type = VariableCollection.dirtStuck;
					type = VariableCollection.nothing;
				} 
			} else if (state == VariableCollection.moveToDirtUp){
				up = true;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step*1) {
					spriteToDraw = StaticSprites.dirtAnimUp[2];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.dirtAnimUp[3];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.dirtAnimUp[4];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.dirtAnimUp[5];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.dirtAnimUp[6];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.dirtAnimUp[7];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.dirtAnimUp[8];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.dirtAnimUp[9];
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.dirtAnimUp[10];
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.dirtAnimUp[11];
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.dirtAnimUp[12];
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.dirtAnimUp[13];
				}  else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.dirtAnimUp[14];
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.dirtAnimUp[15];
				} else {
					locked = false;
					sim.map.terrainBlocks[tileX][tileY].type = VariableCollection.dirtStuck;
					type = VariableCollection.nothing;
				} 
			} else if (state == VariableCollection.moveToDirtDown){
				up = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step*1) {
					spriteToDraw = StaticSprites.dirtAnimDown[2];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.dirtAnimDown[3];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.dirtAnimDown[4];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.dirtAnimDown[5];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.dirtAnimDown[6];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.dirtAnimDown[7];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.dirtAnimDown[8];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.dirtAnimDown[9];
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.dirtAnimDown[10];
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.dirtAnimDown[11];
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.dirtAnimDown[12];
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.dirtAnimDown[13];
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.dirtAnimDown[14];
				} else {
					locked = false;
					sim.map.terrainBlocks[tileX][tileY].type = VariableCollection.dirtStuck;
					type = VariableCollection.nothing;
				} 
			}
		} else if (type == VariableCollection.goal) { 
			int step = 140;
			animStep2 += Gdx.graphics.getDeltaTime()*1000;
			if (animStep2 <= step) {
				spriteToDraw = StaticSprites.goal[0];
			} else if (animStep2 <= step*2){
				spriteToDraw = StaticSprites.goal[1];
			} else if (animStep2 <= step*3){
				spriteToDraw = StaticSprites.goal[2];
			} else if (animStep2 <= step*4){
				spriteToDraw = StaticSprites.goal[3];
			} else if (animStep2 <= step*5){
				spriteToDraw = StaticSprites.goal[4];
			} else {
				animStep2 = 0;
			}
		} else if (type == VariableCollection.boulder) { 
			if(state == VariableCollection.boulderFalling){
				sim.map.renderAtRows.get(tileY).removeValue(sim.map.blocks[tileX][tileY],true);
				sim.map.blocks[tileX][tileY] = new Block(VariableCollection.nothing,tileX,tileY);
			} else if (state == VariableCollection.boulderMoveRight) {
				int step = 40;
				right = true;
				up = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.boulderRight[1];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.boulderRight[2];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.boulderRight[3];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.boulderRight[4];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.boulderRight[5];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.boulderRight[6];
				} else if (animStep2 <=step*7){
					spriteToDraw = StaticSprites.boulderRight[7];
				} else {
					locked = false;
					right = false;
					spriteToDraw = StaticSprites.boulderBase;
					if (sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.hole) {
						this.state = VariableCollection.boulderFalling;
					} else {
						if (!this.moveRight(sim))
							state = VariableCollection.inactive;
						else
							spriteToDraw = StaticSprites.boulderRight[1];
					}
				}
			} else if (state == VariableCollection.boulderMoveLeft) {
				int step =40;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				right = false;
				up = false;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.boulderRight[7];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.boulderRight[6];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.boulderRight[5];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.boulderRight[4];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.boulderRight[3];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.boulderRight[2];
				} else if (animStep2 <=step*7){
					spriteToDraw = StaticSprites.boulderRight[1];
				} else {
					spriteToDraw = StaticSprites.boulderBase;
					locked = false;
					if (sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.hole) {
						this.state = VariableCollection.boulderFalling;
					} else {
						if (!this.moveLeft(sim))
							state = VariableCollection.inactive;
						else
							spriteToDraw = StaticSprites.boulderRight[7];
					}
				}
			} else if (state == VariableCollection.boulderMoveUp) {
				int step = 40;
				up = true;
				right = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.boulderDown[7];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.boulderDown[6];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.boulderDown[5];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.boulderDown[4];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.boulderDown[3];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.boulderDown[2];
				} else if (animStep2 <=step*7){
					spriteToDraw = StaticSprites.boulderDown[1];
				} else {
					locked = false;
					spriteToDraw = StaticSprites.boulderBase;
					if (sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.hole) {
						this.state = VariableCollection.boulderFalling;
					} else {
						if (!this.moveUp(sim)) {
							state = VariableCollection.inactive;
							up = false;
						} else
							spriteToDraw = StaticSprites.boulderDown[7];
					}
				}
			} else if (state == VariableCollection.boulderMoveDown) {
				int step = 40;
				up = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.boulderDown[1];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.boulderDown[2];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.boulderDown[3];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.boulderDown[4];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.boulderDown[5];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.boulderDown[6];
				} else if (animStep2 <=step*7){
					spriteToDraw = StaticSprites.boulderDown[7];
				} else {
					locked = false;
					spriteToDraw = StaticSprites.boulderBase;
					if (sim.map.terrainBlocks[tileX][tileY].type == VariableCollection.hole) {
						this.state = VariableCollection.boulderFalling;
					} else {
						if (!this.moveDown(sim))
							state = VariableCollection.inactive;
					}
				}
			}
		} else if (type == VariableCollection.mergeblock) {
			if (state == VariableCollection.mergeMergeHoriRight){
				int step = 60;
				up = false;
				right = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.mergeMergeHori[0];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.mergeMergeHori[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.mergeMergeHori[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.mergeMergeHori[3];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.mergeMergeHori[4];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.mergeMergeHori[5];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.mergeMergeHori[6];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.mergeMergeHori[7];
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.mergeMergeHori[8];
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.mergeMergeHori[9];
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.mergeMergeHori[10];
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.mergeMergeHori[11];
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.mergeMergeHori[12];
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.mergeMergeHori[13];
				} else if (animStep2 <= step*15){
					spriteToDraw = StaticSprites.mergeMergeHori[14];
				} else if (animStep2 <= step*16){
					spriteToDraw = StaticSprites.mergeMergeHori[15];
				} else if (animStep2 <= step*17){
					spriteToDraw = StaticSprites.mergeMergeHori[16];
				} else if (animStep2 <= step*18){
					spriteToDraw = StaticSprites.mergeMergeHori[17];
				} else if (animStep2 <= step*19){
					spriteToDraw = StaticSprites.mergeMergeHori[18];
				} else if (animStep2 <= step*20){
					spriteToDraw = StaticSprites.mergeMergeHori[19];
				} else if (animStep2 <= step*21){
					spriteToDraw = StaticSprites.mergeMergeHori[20];
				} else if (animStep2 <= step*22){
					spriteToDraw = StaticSprites.mergeMergeHori[21];
				} else {
					locked = false;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[0];
					state = VariableCollection.inactive;
					type = VariableCollection.nothing;
					sim.map.renderAtRows.get(tileY).removeValue(sim.map.blocks[tileX][tileY], true);
					animStep2 = 0;
					locked = false;
				}
			} else if (state == VariableCollection.mergeMergeHoriLeft){
				int step = 60;
				up = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				right = true;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.mergeMergeHori[0];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.mergeMergeHori[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.mergeMergeHori[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.mergeMergeHori[3];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.mergeMergeHori[4];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.mergeMergeHori[5];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.mergeMergeHori[6];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.mergeMergeHori[7];
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.mergeMergeHori[8];
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.mergeMergeHori[9];
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.mergeMergeHori[10];
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.mergeMergeHori[11];
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.mergeMergeHori[12];
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.mergeMergeHori[13];
				} else if (animStep2 <= step*15){
					spriteToDraw = StaticSprites.mergeMergeHori[14];
				} else if (animStep2 <= step*16){
					spriteToDraw = StaticSprites.mergeMergeHori[15];
				} else if (animStep2 <= step*17){
					spriteToDraw = StaticSprites.mergeMergeHori[16];
				} else if (animStep2 <= step*18){
					spriteToDraw = StaticSprites.mergeMergeHori[17];
				} else if (animStep2 <= step*19){
					spriteToDraw = StaticSprites.mergeMergeHori[18];
				} else if (animStep2 <= step*20){
					spriteToDraw = StaticSprites.mergeMergeHori[19];
				} else if (animStep2 <= step*21){
					spriteToDraw = StaticSprites.mergeMergeHori[20];
				} else if (animStep2 <= step*22){
					spriteToDraw = StaticSprites.mergeMergeHori[21];
				} else {
					locked = false;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[0];
					state = VariableCollection.inactive;
					animStep2 = 0;
					right = false;
					locked = false;
					type = VariableCollection.nothing;
					sim.map.renderAtRows.get(tileY).removeValue(this,true);
				}
			} else if (state == VariableCollection.mergeMergeVertiDown){
				int step = 60;
				up = true;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				right = false;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.mergeMergeVerti[0];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.mergeMergeVerti[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.mergeMergeVerti[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.mergeMergeVerti[3];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.mergeMergeVerti[4];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.mergeMergeVerti[5];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.mergeMergeVerti[6];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.mergeMergeVerti[7];
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.mergeMergeVerti[8];
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.mergeMergeVerti[9];
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.mergeMergeVerti[10];
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.mergeMergeVerti[11];
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.mergeMergeVerti[12];
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.mergeMergeVerti[13];
				} else if (animStep2 <= step*15){
					spriteToDraw = StaticSprites.mergeMergeVerti[14];
				} else if (animStep2 <= step*16){
					spriteToDraw = StaticSprites.mergeMergeVerti[15];
				} else if (animStep2 <= step*17){
					spriteToDraw = StaticSprites.mergeMergeVerti[16];
				} else if (animStep2 <= step*18){
					spriteToDraw = StaticSprites.mergeMergeVerti[17];
				} else if (animStep2 <= step*19){
					spriteToDraw = StaticSprites.mergeMergeVerti[18];
				} else if (animStep2 <= step*20){
					spriteToDraw = StaticSprites.mergeMergeVerti[19];
				} else if (animStep2 <= step*21){
					spriteToDraw = StaticSprites.mergeMergeVerti[20];
				} else if (animStep2 <= step*22){
					spriteToDraw = StaticSprites.mergeMergeVerti[21];
				} else {
					locked = false;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[0];
					state = VariableCollection.inactive;
					animStep2 = 0;
					right = false;
					locked = false;
					type = VariableCollection.nothing;
					sim.map.renderAtRows.get(tileY).removeValue(this,true);
				}
			} else if (state == VariableCollection.mergeMergeVertiUp){
				int step = 60;
				up = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				right = false;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.mergeMergeVerti[0];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.mergeMergeVerti[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.mergeMergeVerti[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.mergeMergeVerti[3];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.mergeMergeVerti[4];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.mergeMergeVerti[5];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.mergeMergeVerti[6];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.mergeMergeVerti[7];
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.mergeMergeVerti[8];
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.mergeMergeVerti[9];
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.mergeMergeVerti[10];
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.mergeMergeVerti[11];
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.mergeMergeVerti[12];
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.mergeMergeVerti[13];
				} else if (animStep2 <= step*15){
					spriteToDraw = StaticSprites.mergeMergeVerti[14];
				} else if (animStep2 <= step*16){
					spriteToDraw = StaticSprites.mergeMergeVerti[15];
				} else if (animStep2 <= step*17){
					spriteToDraw = StaticSprites.mergeMergeVerti[16];
				} else if (animStep2 <= step*18){
					spriteToDraw = StaticSprites.mergeMergeVerti[17];
				} else if (animStep2 <= step*19){
					spriteToDraw = StaticSprites.mergeMergeVerti[18];
				} else if (animStep2 <= step*20){
					spriteToDraw = StaticSprites.mergeMergeVerti[19];
				} else if (animStep2 <= step*21){
					spriteToDraw = StaticSprites.mergeMergeVerti[20];
				} else if (animStep2 <= step*22){
					spriteToDraw = StaticSprites.mergeMergeVerti[21];
				} else {
					locked = false;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[0];
					state = VariableCollection.inactive;
					animStep2 = 0;
					right = false;
					locked = false;
					type = VariableCollection.nothing;
					sim.map.renderAtRows.get(tileY).removeValue(this,true);
				}
			} else if (state == VariableCollection.mergeMoveLeft) {
				right = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.mergeLeft[0];
					lampX = 64;
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.mergeLeft[1];
					lampX = 60;
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.mergeLeft[2];
					lampX = 56;
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.mergeLeft[3];
					lampX = 52;
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.mergeLeft[4];
					lampX = 48;
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.mergeLeft[5];
					lampX = 44;
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.mergeLeft[6];
					lampX = 40;
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.mergeLeft[7];
					lampX = 36;
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.mergeLeft[8];
					lampX = 32;
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.mergeLeft[9];
					lampX = 28;
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.mergeLeft[10];
					lampX = 24;
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.mergeLeft[11];
					lampX = 20;
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.mergeLeft[12];
					lampX = 16;
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.mergeLeft[13];
					lampX = 12;
				} else if (animStep2 <= step*15){
					spriteToDraw = StaticSprites.mergeLeft[14];
					lampX = 8;
				} else if (animStep2 <= step*16){
					spriteToDraw = StaticSprites.mergeLeft[15];
					lampX = 4;
				} else if (animStep2 <= step*17){
					spriteToDraw = StaticSprites.mergeLeft[16];
					lampX = 0;
				} else if (animStep2 <= step*18){
					spriteToDraw = StaticSprites.mergeLeft[17];
					lampX = -4;
				} else if (animStep2 <= step*19){
					spriteToDraw = StaticSprites.mergeLeft[18];
					lampX = -8;
				} else if (animStep2 <= step*20){
					spriteToDraw = StaticSprites.mergeLeft[19];
					lampX = -4;
				} else if (animStep2 <= step*21){
					spriteToDraw = StaticSprites.mergeLeft[20];
					lampX = 0;
				} else {
					lampX = 0;
					right = false;
					locked = false;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[4];
					state = VariableCollection.inactive;;
					animStep2 = 800;
				}
			} else if (state == VariableCollection.mergeMoveRight) {
				right = true;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.mergeRight[0];
					lampX = -64;
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.mergeRight[1];
					lampX = -60;
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.mergeRight[2];
					lampX = -56;
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.mergeRight[3];
					lampX = -52;
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.mergeRight[4];
					lampX = -48;
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.mergeRight[5];
					lampX = -44;
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.mergeRight[6];
					lampX = -40;
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.mergeRight[7];
					lampX = -36;
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.mergeRight[8];
					lampX = -32;
				} else if (animStep2 <= step*10){
					spriteToDraw = StaticSprites.mergeRight[9];
					lampX = -28;
				} else if (animStep2 <= step*11){
					spriteToDraw = StaticSprites.mergeRight[10];
					lampX = -24;
				} else if (animStep2 <= step*12){
					spriteToDraw = StaticSprites.mergeRight[11];
					lampX = -20;
				} else if (animStep2 <= step*13){
					spriteToDraw = StaticSprites.mergeRight[12];
					lampX = -16;
				} else if (animStep2 <= step*14){
					spriteToDraw = StaticSprites.mergeRight[13];
					lampX = -12;
				} else if (animStep2 <= step*15){
					spriteToDraw = StaticSprites.mergeRight[14];
					lampX = -8;
				} else if (animStep2 <= step*16){
					spriteToDraw = StaticSprites.mergeRight[15];
					lampX = -4;
				} else if (animStep2 <= step*17){
					spriteToDraw = StaticSprites.mergeRight[16];
					lampX = 0;
				} else if (animStep2 <= step*18){
					spriteToDraw = StaticSprites.mergeRight[17];
					lampX = 4;
				} else if (animStep2 <= step*19){
					spriteToDraw = StaticSprites.mergeRight[18];
					lampX = 8;
				} else if (animStep2 <= step*20){
					spriteToDraw = StaticSprites.mergeRight[19];
					lampX = 4;
				} else if (animStep2 <= step*21){
					spriteToDraw = StaticSprites.mergeRight[20];
					lampX = 0;
				} else {
					lampX = 0;
					right = false;
					locked = false;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[4];
					state = VariableCollection.inactive;;
					animStep2 = 800;
				}
			} else if (state == VariableCollection.mergeMoveDown) {
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.mergeDown[0];
					lampY = 64;
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.mergeDown[1];
					lampY = 59;
				} else if (animStep2 <= step*3){
					lampY = 54;
					spriteToDraw = StaticSprites.mergeDown[2];
				} else if (animStep2 <= step*4){
					lampY = 49;
					spriteToDraw = StaticSprites.mergeDown[3];
				} else if (animStep2 <= step*5){
					lampY = 43;
					spriteToDraw = StaticSprites.mergeDown[4];
				} else if (animStep2 <= step*6){
					lampY = 38;
					spriteToDraw = StaticSprites.mergeDown[5];
				} else if (animStep2 <= step*7){
					lampY = 33;
					spriteToDraw = StaticSprites.mergeDown[6];
				} else if (animStep2 <= step*8){
					lampY = 28;
					spriteToDraw = StaticSprites.mergeDown[7];
				} else if (animStep2 <= step*9){
					lampY = 23;
					spriteToDraw = StaticSprites.mergeDown[8];
				} else if (animStep2 <= step*10){
					lampY = 18;
					spriteToDraw = StaticSprites.mergeDown[9];
				} else if (animStep2 <= step*11){
					lampY = 13;
					spriteToDraw = StaticSprites.mergeDown[10];
				} else if (animStep2 <= step*12){
					lampY = 8;
					spriteToDraw = StaticSprites.mergeDown[11];
				} else if (animStep2 <= step*13){
					lampY = 3;
					spriteToDraw = StaticSprites.mergeDown[12];
				} else if (animStep2 <= step*14){
					lampY = -1;
					spriteToDraw = StaticSprites.mergeDown[13];
				} else if (animStep2 <= step*15){
					lampY = -4;
					spriteToDraw = StaticSprites.mergeDown[14];
				} else {
					lampY = 0;
					locked = false;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[4];
					state = VariableCollection.inactive;;
					animStep2 = 800;
				}
			} else if (state == VariableCollection.mergeMoveUp) {
				up = true;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				int step = 40;
				if (animStep2 <= step) {
					lampY = -64;
					spriteToDraw = StaticSprites.mergeUp[0];
				} else if (animStep2 <= step*2){
					lampY = -59;
					spriteToDraw = StaticSprites.mergeUp[1];
				} else if (animStep2 <= step*3){
					lampY = -54;
					spriteToDraw = StaticSprites.mergeUp[2];
				} else if (animStep2 <= step*4){
					lampY = -49;
					spriteToDraw = StaticSprites.mergeUp[3];
				} else if (animStep2 <= step*5){
					lampY = -44;
					spriteToDraw = StaticSprites.mergeUp[4];
				} else if (animStep2 <= step*6){
					lampY = -39;
					spriteToDraw = StaticSprites.mergeUp[5];
				} else if (animStep2 <= step*7){
					lampY = -34;
					spriteToDraw = StaticSprites.mergeUp[6];
				} else if (animStep2 <= step*8){
					lampY = -29;
					spriteToDraw = StaticSprites.mergeUp[7];
				} else if (animStep2 <= step*9){
					lampY = -24;
					spriteToDraw = StaticSprites.mergeUp[8];
				} else if (animStep2 <= step*10){
					lampY = -19;
					spriteToDraw = StaticSprites.mergeUp[9];
				} else if (animStep2 <= step*11){
					lampY = -14;
					spriteToDraw = StaticSprites.mergeUp[10];
				} else if (animStep2 <= step*12){
					lampY = -9;
					spriteToDraw = StaticSprites.mergeUp[11];
				} else if (animStep2 <= step*13){
					lampY = -4;
					spriteToDraw = StaticSprites.mergeUp[12];
				} else if (animStep2 <= step*14){
					lampY = 1;
					spriteToDraw = StaticSprites.mergeUp[13];
				} else {
					lampY = 0;
					up = false;
					locked = false;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[4];
					state = VariableCollection.inactive;;
					animStep2 = 800;
				}
			} else if (state == VariableCollection.inactive) {
				int step = 150;
				up = false;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[0];
					lampY = 0;
					lightScale = 2.2f;
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[1];
					lampY = 3;
					lightScale = 2.16f;
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[2];
					lampY = 6;
					lightScale = 2.12f;
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[3];
					lampY = 9;
					lightScale = 2.08f;
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[4];
					lampY = 12;
					lightScale = 2.04f;
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[5];
					lampY = 15;
					lightScale = 2.0f;
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[4];
					lampY = 12;
					lightScale = 2.04f;
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[3];
					lampY = 9;
					lightScale = 2.08f;
				} else if (animStep2 <= step*9){
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[2];
					lampY = 6;
					lightScale = 2.12f;
				} else {
					lightScale = 2.16f;
					lampY = 3;
					spriteToDraw = StaticSprites.mergeBlockBaseAnim[1];
					animStep2 = 0;
				}
			}
		}else if (type == VariableCollection.door_red) {  
			if (state == VariableCollection.dooropen) {
				int step = 80;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.dooropening[1];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.dooropening[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.dooropening[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.dooropening[2];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.dooropening[3];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.dooropening[4];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.dooropening[5];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.dooropening[6];
				} else {
					locked = false;
					type = VariableCollection.nothing;
					state = VariableCollection.inactive;
				}
			}
		} else if (type == VariableCollection.door_blue) {
			if (state == VariableCollection.dooropenB) {
				int step = 80;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.dooropeningB[1];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.dooropeningB[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.dooropeningB[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.dooropeningB[2];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.dooropeningB[3];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.dooropeningB[4];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.dooropeningB[5];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.dooropeningB[6];
				} else {
					locked = false;
					type = VariableCollection.nothing;
					state = VariableCollection.inactive;
				}
			}
		} else if (type == VariableCollection.door_yellow) {
			if (state == VariableCollection.dooropenY) {
				int step = 80;
				animStep2 += Gdx.graphics.getDeltaTime()*1000;
				if (animStep2 <= step) {
					spriteToDraw = StaticSprites.dooropeningY[1];
				} else if (animStep2 <= step*2){
					spriteToDraw = StaticSprites.dooropeningY[1];
				} else if (animStep2 <= step*3){
					spriteToDraw = StaticSprites.dooropeningY[2];
				} else if (animStep2 <= step*4){
					spriteToDraw = StaticSprites.dooropeningY[2];
				} else if (animStep2 <= step*5){
					spriteToDraw = StaticSprites.dooropeningY[3];
				} else if (animStep2 <= step*6){
					spriteToDraw = StaticSprites.dooropeningY[4];
				} else if (animStep2 <= step*7){
					spriteToDraw = StaticSprites.dooropeningY[5];
				} else if (animStep2 <= step*8){
					spriteToDraw = StaticSprites.dooropeningY[6];
				} else {
					locked = false;
					type = VariableCollection.nothing;
					state = VariableCollection.inactive;
				}
			}
		} else if (type == VariableCollection.key_red) {
			int step = 200;
			if (moveTimer < step)
				spriteToDraw = StaticSprites.redkey[0];
			else if (moveTimer < step*2)
				spriteToDraw = StaticSprites.redkey[1];
			else if (moveTimer < step*3)
				spriteToDraw = StaticSprites.redkey[2];
			else if (moveTimer < step*4)
				spriteToDraw = StaticSprites.redkey[3];
			else if (moveTimer < step*5)
				spriteToDraw = StaticSprites.redkey[4];
			else {
				spriteToDraw = StaticSprites.redkey[0];
				moveTimer = -10000;
			}
		} else if (type == VariableCollection.key_blue) {
			int step = 200;
			if (moveTimer < step)
				spriteToDraw = StaticSprites.bluekey[0];
			else if (moveTimer < step*2)
				spriteToDraw = StaticSprites.bluekey[1];
			else if (moveTimer < step*3)
				spriteToDraw = StaticSprites.bluekey[2];
			else if (moveTimer < step*4)
				spriteToDraw = StaticSprites.bluekey[3];
			else if (moveTimer < step*5)
				spriteToDraw = StaticSprites.bluekey[4];
			else {
				spriteToDraw = StaticSprites.bluekey[0];
				moveTimer = 0;
			}
		} else if (type == VariableCollection.key_yellow) {
			int step = 200;
			if (moveTimer < step)
				spriteToDraw = StaticSprites.yellowkey[0];
			else if (moveTimer < step*2)
				spriteToDraw = StaticSprites.yellowkey[1];
			else if (moveTimer < step*3)
				spriteToDraw = StaticSprites.yellowkey[2];
			else if (moveTimer < step*4)
				spriteToDraw = StaticSprites.yellowkey[3];
			else if (moveTimer < step*5)
				spriteToDraw = StaticSprites.yellowkey[4];
			else {
				spriteToDraw = StaticSprites.yellowkey[0];
				moveTimer = 0;
			}
		}
	}
	public boolean moveRight(Simulation sim) {
		if (locked)
			return false;
		if (type == VariableCollection.moveBlock) {
			if (sim.map.blocks[tileX+1][tileY].type == VariableCollection.nothing  ) {
				if (sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.grass|| sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.button || sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.button_blue|| sim.map.terrainBlocks[tileX+1][tileY].state == VariableCollection.pillardown || sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.thefilledhole) { 
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX+1][tileY];
					sim.map.blocks[tileX+1][tileY] = b1;
					state = VariableCollection.blockMoveRight;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX += 1;
					animStep2 = 0;
					moveTimer = 0;
					locked = true;
					return true;
				} else if (sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.hole) {
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX+1][tileY];
					sim.map.blocks[tileX+1][tileY] = b1;
					state = VariableCollection.blockMoveRight;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX += 1;
					moveTimer = 0;
					animStep2 = 0;
					locked = true;
					return true;
				}
				else if (sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.dirt) {
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX+1][tileY];
					sim.map.blocks[tileX+1][tileY] = b1;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX += 1;
					moveTimer = 0;
					animStep2 = 0;
					state = VariableCollection.moveToDirtRight;
					locked = true;
					return true;
				}
			}
		} else if (type == VariableCollection.boulder) {
			if(sim.map.blocks.length > tileX+1) {
				if ((sim.map.blocks[tileX+1][tileY].type == VariableCollection.nothing && sim.map.terrainBlocks[tileX+1][tileY].type != VariableCollection.dirtStuck&& sim.map.terrainBlocks[tileX+1][tileY].state != VariableCollection.pillarup) || sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.thefilledhole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX+1][tileY];
					b1.state = VariableCollection.boulderMoveRight;
					sim.map.blocks[tileX+1][tileY] = b1;
					if(sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.dirt){
						sim.map.terrainBlocks[tileX+1][tileY].type = VariableCollection.dirtboulderright;
						sim.map.terrainBlocks[tileX+1][tileY].dirtTimer = 0;
					}
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX += 1;
					moveTimer = 0;
					animStep2 =0;
					return true;
				}
			}
		} else if (type == VariableCollection.mergeblock) {
			if (sim.map.blocks[tileX+1][tileY].type == VariableCollection.nothing) {
				if (sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.dirt || sim.map.terrainBlocks[tileX+1][tileY].state == VariableCollection.pillardown||sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.grass|| sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.button || sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.button_blue ||sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.hole || sim.map.terrainBlocks[tileX+1][tileY].type == VariableCollection.thefilledhole) {
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX+1][tileY];
					sim.map.blocks[tileX+1][tileY] = b1;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX += 1;
					animStep2 = 0;
					moveTimer = 0;
					locked = true;
					state = VariableCollection.mergeMoveRight;
					return true;
				}
			} else if(sim.map.blocks[tileX+1][tileY].type == VariableCollection.mergeblock){
				if (sim.map.blocks[tileX+1][tileY].locked)
					return false;
				state = VariableCollection.mergeMergeHoriRight;
				sim.map.blocks[tileX+1][tileY].type = VariableCollection.nothing;
				sim.map.renderAtRows.get(tileY).removeValue(sim.map.blocks[tileX+1][tileY], true);
				locked = true;
				moveTimer = 0;
				animStep2 = 0;
				return true;
			}
		}
		return false;
	}
	public boolean moveLeft(Simulation sim) {
		if (locked)
			return false;
		if (type == VariableCollection.moveBlock) {
			if (sim.map.blocks[tileX-1][tileY].type == VariableCollection.nothing) {
				if (sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.grass|| sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.button || sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.button_blue|| sim.map.terrainBlocks[tileX-1][tileY].state == VariableCollection.pillardown || sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.thefilledhole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX-1][tileY];
					sim.map.blocks[tileX-1][tileY] = b1;
					state = VariableCollection.blockMoveLeft;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX -= 1;
					moveTimer = 0;
					animStep2 = 0;
					return true;
				} else if (sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.hole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX-1][tileY];
					sim.map.blocks[tileX-1][tileY] = b1;
					state = VariableCollection.blockMoveLeft;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX -= 1;
					animStep2 = 0;
					moveTimer = 0;
					return true;
				} else if (sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.dirt) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX-1][tileY];
					sim.map.blocks[tileX-1][tileY] = b1;
					state = VariableCollection.moveToDirtLeft;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX -= 1;
					animStep2 = 0;
					moveTimer = 0;
					return true;
				}
			}
		} else if (type == VariableCollection.boulder) {
			if(tileX > 0)
			{
				if ((sim.map.blocks[tileX-1][tileY].type == VariableCollection.nothing  && sim.map.terrainBlocks[tileX-1][tileY].type != VariableCollection.dirtStuck&& sim.map.terrainBlocks[tileX-1][tileY].state != VariableCollection.pillarup )|| sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.thefilledhole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX-1][tileY];
					b1.state = VariableCollection.boulderMoveLeft;
					if(sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.dirt){
						sim.map.terrainBlocks[tileX-1][tileY].type = VariableCollection.dirtboulder;
						sim.map.terrainBlocks[tileX-1][tileY].dirtTimer = 0;
					}
					sim.map.blocks[tileX-1][tileY] = b1;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX -= 1;
					animStep2 =0;
					moveTimer = 0;
					return true;
				}
			}
		} else if (type == VariableCollection.mergeblock) {
			if (sim.map.blocks[tileX-1][tileY].type == VariableCollection.nothing ) {
				if (sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.dirt || sim.map.terrainBlocks[tileX-1][tileY].state == VariableCollection.pillardown||sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.grass || sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.button_blue ||sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.button|| sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.hole || sim.map.terrainBlocks[tileX-1][tileY].type == VariableCollection.thefilledhole) { 
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX-1][tileY];
					sim.map.blocks[tileX-1][tileY] = b1;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileX -= 1;
					animStep2 = 0;
					moveTimer = 0;
					locked = true;
					state = VariableCollection.mergeMoveLeft;
					return true;
				}
			} else if(sim.map.blocks[tileX-1][tileY].type == VariableCollection.mergeblock){
				if (sim.map.blocks[tileX-1][tileY].locked)
					return false;
				state = VariableCollection.mergeMergeHoriLeft;
				sim.map.renderAtRows.get(tileY).removeValue(sim.map.blocks[tileX-1][tileY], true);
				sim.map.blocks[tileX-1][tileY].type = VariableCollection.nothing;
				moveTimer = 0;
				animStep2 = 0;
				locked = true;
				return true;
			}
		}
		return false;
	}
	public boolean moveDown(Simulation sim) {
		if (locked)
			return false;
		if (type == VariableCollection.moveBlock) {
			if (sim.map.blocks[tileX][tileY-1].type == VariableCollection.nothing) {
				if (sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.grass || sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.button|| sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.button_blue|| sim.map.terrainBlocks[tileX][tileY-1].state == VariableCollection.pillardown || sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.thefilledhole ) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY-1];
					sim.map.blocks[tileX][tileY-1] = b1;
					state = VariableCollection.blockMoveDown;
					sim.map.blocks[tileX][tileY].tileY = tileY;
					tileY -= 1;
					animStep2 = 0;
					moveTimer = 0;
					sim.map.renderAtRows.get(renderAtRow).removeValue(this, true);
					renderAtRow--;
					sim.map.renderAtRows.get(renderAtRow).add(this);
					return true;
				} else if (sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.hole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY-1];
					sim.map.blocks[tileX][tileY-1] = b1;
					state = VariableCollection.blockMoveDown;
					sim.map.blocks[tileX][tileY].tileY = tileY;
					tileY -= 1;
					animStep2 = 0;
					moveTimer = 0;
					sim.map.renderAtRows.get(renderAtRow).removeValue(this, true);
					renderAtRow--;
					sim.map.renderAtRows.get(renderAtRow).add(this);
					return true;
				} else if (sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.dirt) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY-1];
					sim.map.blocks[tileX][tileY-1] = b1;
					state = VariableCollection.moveToDirtDown;
					sim.map.blocks[tileX][tileY].tileY = tileY;
					tileY -= 1;
					animStep2 = 0;
					moveTimer = 0;
					sim.map.renderAtRows.get(renderAtRow).removeValue(this, true);
					renderAtRow--;
					sim.map.renderAtRows.get(renderAtRow).add(this);
					return true;
				} 
			}
		} else if (type == VariableCollection.boulder) {
			if(tileY > 0) {
				if ((sim.map.blocks[tileX][tileY-1].type == VariableCollection.nothing && sim.map.terrainBlocks[tileX][tileY-1].type != VariableCollection.dirtStuck && sim.map.terrainBlocks[tileX][tileY-1].state != VariableCollection.pillarup ) || sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.thefilledhole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY-1];
					b1.state = VariableCollection.boulderMoveDown;
					sim.map.blocks[tileX][tileY-1] = b1;
					if(sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.dirt){
						sim.map.terrainBlocks[tileX][tileY-1].type = VariableCollection.dirtboulderdown;
						sim.map.terrainBlocks[tileX][tileY-1].dirtTimer = 0;
					}
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileY -= 1;
					moveTimer = 0;
					animStep2 = 0;
					sim.map.renderAtRows.get(renderAtRow).removeValue(this, true);
					renderAtRow--;
					sim.map.renderAtRows.get(renderAtRow).add(this);
					return true;
				}
			}
		} else if (type == VariableCollection.mergeblock) {
			if (sim.map.blocks[tileX][tileY-1].type == VariableCollection.nothing ) {
				if (sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.dirt || sim.map.terrainBlocks[tileX][tileY-1].state == VariableCollection.pillardown||sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.grass || sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.button_blue|| sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.button|| sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.hole || sim.map.terrainBlocks[tileX][tileY-1].type == VariableCollection.thefilledhole) { 
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY-1];
					sim.map.blocks[tileX][tileY-1] = b1;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileY -= 1;
					animStep2 = 0;
					moveTimer = 0;
					locked = true;
					state = VariableCollection.mergeMoveDown;
					return true;
				}
			} else if(sim.map.blocks[tileX][tileY-1].type == VariableCollection.mergeblock){
				if (sim.map.blocks[tileX][tileY-1].locked)
					return false;
				locked = true;
				state = VariableCollection.mergeMergeVertiDown;
				sim.map.blocks[tileX][tileY-1].type = VariableCollection.nothing;
				sim.map.renderAtRows.get(tileY-1).removeValue(sim.map.blocks[tileX][tileY-1], true);
				moveTimer = 0;
				animStep2 = 0;
				return true;
			}
		}
		return false;
	}
	public boolean moveUp(Simulation sim) {
		if (locked)
			return false;
		if (type == VariableCollection.moveBlock) {
			if (sim.map.blocks[tileX][tileY+1].type == VariableCollection.nothing) {
				if (sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.grass || sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.button|| sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.button_blue || sim.map.terrainBlocks[tileX][tileY+1].state == VariableCollection.pillardown || sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.thefilledhole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY+1];
					sim.map.blocks[tileX][tileY+1] = b1;
					state = VariableCollection.blockMoveUp;
					sim.map.blocks[tileX][tileY].tileY = tileY;
					tileY += 1;
					moveTimer = 0;
					animStep2 = 0;
					return true;
				} else if (sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.hole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY+1];
					sim.map.blocks[tileX][tileY+1] = b1;
					state = VariableCollection.blockMoveUp;
					sim.map.blocks[tileX][tileY].tileY = tileY;
					tileY += 1;
					moveTimer = 0;
					animStep2 = 0;
					return true;
				} else if (sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.dirt) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY+1];
					sim.map.blocks[tileX][tileY+1] = b1;
					state = VariableCollection.moveToDirtUp;
					sim.map.blocks[tileX][tileY].tileY = tileY;
					tileY += 1;
					moveTimer = 0;
					animStep2 = 0;
					return true;
				}
			} 
		} else if (type == VariableCollection.boulder) {
			if(sim.map.blocks[tileX].length > tileY + 1) {
				if (sim.map.blocks[tileX][tileY+1].type == VariableCollection.nothing && sim.map.terrainBlocks[tileX][tileY+1].type != VariableCollection.dirtStuck && sim.map.terrainBlocks[tileX][tileY+1].state != VariableCollection.pillarup || sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.button || sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.thefilledhole) {
					locked = true;
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY+1];
					b1.state = VariableCollection.boulderMoveUp;
					sim.map.blocks[tileX][tileY+1] = b1;
					if(sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.dirt){
						sim.map.terrainBlocks[tileX][tileY+1].type = VariableCollection.dirtboulderup;
						sim.map.terrainBlocks[tileX][tileY+1].dirtTimer = 0;
					}
					sim.map.blocks[tileX][tileY].tileY = tileY;
					tileY += 1;
					moveTimer = 0;
					animStep2 = 0;
					sim.map.renderAtRows.get(renderAtRow).removeValue(this, true);
					renderAtRow++;
					sim.map.renderAtRows.get(renderAtRow).add(this);
					return true;
				}
			}
		} else if (type == VariableCollection.mergeblock) {
			if (sim.map.blocks[tileX][tileY+1].type == VariableCollection.nothing){
				if (sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.dirt || sim.map.terrainBlocks[tileX][tileY+1].state == VariableCollection.pillardown || sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.grass|| sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.button_blue || sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.button || sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.hole|| sim.map.terrainBlocks[tileX][tileY+1].type == VariableCollection.thefilledhole) { 
					Block b1 = sim.map.blocks[tileX][tileY];
					sim.map.blocks[tileX][tileY] = sim.map.blocks[tileX][tileY+1];
					sim.map.blocks[tileX][tileY+1] = b1;
					sim.map.blocks[tileX][tileY].tileX = tileX;
					tileY += 1;
					animStep2 = 0;
					moveTimer = 0;
					locked = true;
					state = VariableCollection.mergeMoveUp;
					return true;
				}
			} else if(sim.map.blocks[tileX][tileY+1].type == VariableCollection.mergeblock){
				if (sim.map.blocks[tileX][tileY+1].locked)
					return false;
				locked = true;
				state = VariableCollection.mergeMergeVertiUp;
				sim.map.blocks[tileX][tileY+1].type = VariableCollection.nothing;
				sim.map.renderAtRows.get(tileY+1).removeValue(sim.map.blocks[tileX][tileY+1], true);
				moveTimer = 0;
				animStep2 = 0;
				return true;
			}
		}

		return false;
	}	
	public void render(SpriteBatch sb,float r,float g,float b,float a) {
		if (type != VariableCollection.nothing) {
			if (right){
				spriteToDraw.setPosition(tileX*64-(spriteToDraw.getWidth()-64), tileY*64);
			} else if(up)
				if (state == VariableCollection.mergeMergeVertiDown || state == VariableCollection.mergeMoveDown)
					spriteToDraw.setPosition(tileX*64-32, tileY*64-70);
				else
					spriteToDraw.setPosition(tileX*64, tileY*64-70);
			else {
				if (state == VariableCollection.mergeMergeVertiUp)
					spriteToDraw.setPosition(tileX*64-32, tileY*64);
				else
					spriteToDraw.setPosition(tileX*64, tileY*64);
			}
			spriteToDraw.setColor(r,g,b,a);
			spriteToDraw.draw(sb);
		}
	}
	public void renderLights(SpriteBatch sb) {
		if (type == VariableCollection.mergeblock) {
			StaticSprites.whitePointLight.setColor(1,1,1,0.5f);
			StaticSprites.whitePointLight.setScale(lightScale);
			StaticSprites.whitePointLight.setPosition(tileX*64+lampX,tileY*64+lampY);
			StaticSprites.whitePointLight.draw(sb);
		} else if (type == VariableCollection.wall && hasLamp) {
			StaticSprites.whitePointLight.setColor(1,1,0,0.5f);
			StaticSprites.whitePointLight.setScale(lightScale);
			StaticSprites.whitePointLight.setPosition(tileX*64+lampX,tileY*64+lampY);
			StaticSprites.whitePointLight.draw(sb);
		}
	}
	public void renderLamps(SpriteBatch sb) {
		if (hasLamp) {
			StaticSprites.lamp.setPosition(tileX*64+lampX,tileY*64+lampY);
			StaticSprites.lamp.draw(sb);
		}
	}
	public String toString() {
		if (type == VariableCollection.boulder)
			return "b";
		else if (type == VariableCollection.door_blue)
			return "db";
		else if (type == VariableCollection.door_red)
			return "dr";
		else if (type == VariableCollection.door_yellow)
			return "dy";
		else if (type == VariableCollection.key_blue)
			return "kb";
		else if (type == VariableCollection.key_red)
			return "kr";
		else if (type == VariableCollection.key_yellow)
			return "ky";
		else if (type == VariableCollection.moveBlock)
			return "m";
		else if (type == VariableCollection.nothing)
			return "n";
		else if (type == VariableCollection.wall)
			return "w";
		else if (type == VariableCollection.goal)
			return "g";
		else if (type == VariableCollection.mergeblock)
			return "me";



		return "n";
	}
}
